package cn.com.cetccst.compliancecheck.demo.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import cn.com.cetccst.compliancecheck.demo.R;

public class ConnectionSetDlg extends AlertDialog.Builder {
    private View view;

    public static void show(Context context, Callback callback) {

        new ConnectionSetDlg(context, callback).show();
    }

    public ConnectionSetDlg(@NonNull Context context, Callback callback) {
        super(context);
        view = LayoutInflater.from(context).inflate(R.layout.connection_set, null, false);
        setView(view)
                .setPositiveButton("确定", (dialog, which) -> {
                    TextView textView = view.findViewById(R.id.offline);
                    callback.handleOffLinePeriod(Integer.parseInt(textView.getText().toString()));
                })
                .setNeutralButton("上线", (dialogInterface, i) -> callback.handleOffLinePeriod(-2))
                .setNegativeButton("关闭检测", (dialogInterface, i) -> callback.handleOffLinePeriod(-1));
    }

    public interface Callback {
        void handleOffLinePeriod(long offline);
    }
}
